﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AiFrame.InterfaceLib.MVP;
using AiFrameDemo.Contacts.Core.ViewModel;
using AiFrameDemo.Contacts.Core.Views;
using AiFrameDemo.Contacts.Lib.Views;
using AiFrameDemo.Lib.Model;

namespace AiFrameDemo.Contacts.WinForms.Windows
{
    public partial class ContactsListFrameBase : UserControl, IContactsListView
    {
        protected ContactsListViewModel _viewModel;

        public ContactsListFrameBase()
        {
            InitializeComponent();
            Dock = DockStyle.Fill;
            dataGridView.Dock = DockStyle.Fill;

            dataGridView.ReadOnly = true;
            dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView.AutoGenerateColumns = false;
            dataGridView.AllowUserToAddRows = false;
            dataGridView.MultiSelect = false;
            

            dataGridView.AlternatingRowsDefaultCellStyle = new DataGridViewCellStyle()
            {
                BackColor = Color.FromArgb(234, 234, 234)
            };

            AddColumns();
        }

        private void AddColumns()
        {
            DataGridViewCell dataGridViewCell = new DataGridViewTextBoxCell();

            dataGridView.Columns.Add(new DataGridViewColumn(dataGridViewCell)
            {
                HeaderText = "Datetime",
                DataPropertyName = "DateTime",
                Width = 250
            });

            dataGridView.Columns.Add(new DataGridViewColumn(dataGridViewCell)
            {
                HeaderText = "Content of meeting",
                DataPropertyName = "Content",
                Width = 200
            });

        }

        public void RefreshView()
        {
            // Refresh actions
        }

        public void SetFree()
        {
            this.Dispose();
        }

        public void SetParentWindow(Control parent)
        {
            this.Parent = parent;
        }

        public virtual void BringWindowToFront()
        {
            this.BringToFront();
        }

        public string GetCaption()
        {
            return "Contacts";
        }

        public void Save()
        {
            throw new NotImplementedException();
        }

        public void SetDataSource(Customer dataSource)
        {
            _viewModel.SetDataSource(dataSource);
        }

        public void BindToViewModel(ContactsListViewModel contactsListViewModel)
        {
            _viewModel = contactsListViewModel;
            dataGridView.DataSource = _viewModel.DataObjectList;
        }

        public int GetSelectedIndex()
        {
            if (dataGridView.SelectedRows.Count == 0)
                return -1;

            return dataGridView.SelectedRows[0].Index;
        }

        public IList<Contact> DataItems
        {
            get { throw new NotImplementedException(); }
        }
    }
}
